package nix.spring.domain;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

// @Component("student")	// 原始写法，下面三种功能相同
// @Service("student")	// service层
// @Controller("student")	// web层
@Repository("student")	// dao层
@Scope(scopeName = "singleton")
public class Student {

	@Value("zhangSan")	// 通过反射的Field赋值（破坏了封装性）
	private String name;
	private Integer age;

	// @Autowired// 自动装配（按类型）
	// @Qualifier("school2")// 指定具体对象
	@Resource(name="school2")//手动指定
	private School school;

	public School getSchool() {
		return school;
	}

	public void setSchool(School school) {
		this.school = school;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	@Value(value = "18")	// 通过set方法赋值（推荐使用）
	public void setAge(Integer age) {
		this.age = age;
	}
	
	@PostConstruct
	public void init() {
		System.out.println("init()...");
	}
	
	@PreDestroy
	public void destroy() {
		System.out.println("destroy()...");
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + ", school=" + school + "]";
	}

}
